<template>
    <div style="height: 100%">
      <a-card title="快捷入口" id="card" class="card">
        <a slot="extra" @click="setting()">
          <span v-if="set">完成</span>
          <a-icon v-else type="setting" theme="filled" />
        </a>
        <a-row style="height: 100%;overflow-y: auto">
          <a-col v-for="(quick,i) in quickPathData" :key="i" v-has="'customer:add'" :span="8" style="text-align: center;padding-top: 5px;">
            <p>
              <a-button
                type="primary"
                size="large"
                :icon="quick.icon"
                shape="circle"
                style="position: relative"
                @click="_click(quick.methods)">
              </a-button>
              <svg @click="delQuickPath(quick.id)" t="1672396021988" v-if="set" class="icon" style="width: 16px;position: absolute; top:0px;cursor:pointer;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2728" width="200" height="200"><path d="M512 32C251.4285715625 32 32 251.4285715625 32 512s219.4285715625 480 480 480 480-219.4285715625 480-480-219.4285715625-480-480-480z m205.7142853125 617.142856875c20.5714284375 20.5714284375 20.5714284375 48 0 61.714286249999994-20.5714284375 20.5714284375-48 20.5714284375-61.714285312499996 0l-137.142856875-137.1428578125L374.857143125 717.7142853125c-20.5714284375 20.5714284375-48 20.5714284375-68.5714284375 0s-20.5714284375-54.857143125 0-68.5714284375l144-144-137.1428578125-137.142856875c-20.5714284375-13.714285312500001-20.5714284375-41.142856875 0-61.714285312499996 20.5714284375-20.5714284375 48-20.5714284375 61.714286249999994 0l137.142856875 137.142856875 144-144c20.5714284375-20.5714284375 48-20.5714284375 68.5714284375 0 20.5714284375 20.5714284375 20.5714284375 48 0 68.5714284375L580.5714284375 512l137.142856875 137.142856875z" fill="#d81e06" p-id="2729"></path></svg>
            </p>
            <p class="text-overflow"><span>{{ quick.name }}</span></p>
          </a-col>
          <a-col v-if="set" :span="6" style="text-align: center;padding-top: 10px;">
            <p>
              <a-button
                type="dashed"
                size="large"
                icon="plus"
                shape="circle"
                @click="addModule()">
              </a-button>
            </p>
            <p><span>添加模块</span></p>
          </a-col>
        </a-row>
      </a-card>
      <a-modal v-model="visible" :footer="null" title="客户查重">
        <div>
          <a-input-search placeholder="请输入查询电话号码" prop="telephone" allowClear enter-button @search="onSearch" />
        </div>
        <p :class="{'show': isTxtShow}" style="text-align: center;margin-top: 20px; color: #a2a2a2">
          {{ message }}
        </p>
        <div :class="{'show': isShow}">
          <a-table :columns="columns" :data-source="data" :pagination="false" bordered>
          </a-table>
        </div>
      </a-modal>
      <draggable ref="draggable" @ok="getQuickPathUser"></draggable>
      <gh-customer-info-modal ref="modalForm"></gh-customer-info-modal>
      <add-customer-contract-modal ref="addCustomerContractModal"></add-customer-contract-modal>
      <goods-rejected-order-modal ref="goodsRejectedOrderModal"></goods-rejected-order-modal>
      <in-depository-order-modal ref="inDepositoryOrderModal"></in-depository-order-modal>
      <other-in-depository-order-modal ref="otherInDepositoryOrderModal"></other-in-depository-order-modal>
      <allocate-and-transfer-modal ref="allocateAndTransferModal"></allocate-and-transfer-modal>
      <purchase-order-modal ref="purchaseOrderModal"></purchase-order-modal>
      <check-modal ref="checkModal"></check-modal>
      <other-out-depository-order-modal ref="otherOutDepositoryOrderModal"></other-out-depository-order-modal>
      <gh-worker-info-modal ref="ghWorkerInfoModal"></gh-worker-info-modal>
    </div>
</template>
<script>
  const columns = [
    {
      title: '客户姓名',
      dataIndex: 'name'
    },
    {
      title: '添加人',
      dataIndex: 'createBy'
    },
    {
      title: '添加时间',
      dataIndex: 'createTime'
    }
  ]
  import GhCustomerInfoModal from "../erp/customer/info/modules/GhCustomerInfoModal";
  import AddCustomerContractModal from "../erp/customer/info/tab/modules/addCustomerContractModal";
  import GoodsRejectedOrderModal from "../erp/supplychain/purchaseGoodsRejectedOrder/modules/goodsRejectedOrderModal";
  import InDepositoryOrderModal from "../erp/supplychain/purchaseInDepositoryOrder/modules/inDepositoryOrderModal";
  import OtherInDepositoryOrderModal from "../erp/supplychain/otherInDepositoryOrder/modules/otherInDepositoryOrderModal";
  import AllocateAndTransferModal from "../erp/supplychain/allocateAndTransfer/modules/allocateAndTransferModal";
  import PurchaseOrderModal from "../erp/supplychain/purchaseOrder/modules/purchaseOrderModal";
  import CheckModal from "../erp/supplychain/makeAnInventory/modules/checkModal";
  import OtherOutDepositoryOrderModal from "../erp/supplychain/otherOutDepositoryOrder/modules/otherOutDepositoryOrderModal";
  import Draggable from "./Draggable"
  import { getAction, deleteAction } from '@/api/manage'
  import GhWorkerInfoModal from '../erp/project/worker/modules/GhWorkerInfoModal'
  import { queryPermissionsByUser } from '@/api/api'
  export default {
    name: "Entrance",
    components: {
      GhCustomerInfoModal,
      AddCustomerContractModal,
      GoodsRejectedOrderModal,
      InDepositoryOrderModal,
      OtherInDepositoryOrderModal,
      AllocateAndTransferModal,
      PurchaseOrderModal,
      CheckModal,
      OtherOutDepositoryOrderModal,
      Draggable,
      GhWorkerInfoModal,
    },
    data() {
      return {
        indexStyle: 1,
        visible: false,
        isShow: true,
        isTxtShow: true,
        set: false,
        data: [],
        quickPathData: [],
        permission: [],
        columns,
        message: '',
        url: {
          getCustomerInfo: '/ghCustomerInfo/getCustomerInfoByTelePhone',
          quickPathListUser: '/quickPathUser/list',
          delete: '/quickPathUser/delete'
        },
        rules: {
          telephone: [
            { required: true, message: "请输入电话号码" }
          ]
        }
      }
    },
    created() {

    },
    mounted(){
      this.getPermission();
      this.getQuickPathUser();
    },
    methods: {
      onStart() {
        this.drag = true;
      },
      onEnd() {
        this.drag = false;
      },
      getQuickPathUser() {
        getAction(this.url.quickPathListUser)
          .then(res => {
            if (res.success) {
              this.quickPathData = res.result;
            }
          });
      },
      addModule() {
        this.module = true;
        this.$refs.draggable.visible = true;
        this.$refs.draggable.quickPathData = this.quickPathData;
        this.$refs.draggable.getQuickPath();
      },
      getPermission() {
        queryPermissionsByUser().then(res => {
          if (res.success) {
            this.permission = res.result;
          }
        })
      },
      // 新增客户
      addCustomer() {
        if(!this.set) {
          let arr = this.permission.menu.findIndex((v) => {
            return v.name == 'customer'
          });
          if(arr == 1) {
            this.$refs.modalForm.visible = true;
            this.$refs.modalForm.title = '新增客户';
          } else {
            this.$message.error('暂无权限');
          }
        }
      },
      // 新增合同
      addContract() {
        if(!this.set) {
          let arr = this.permission.menu.findIndex((v) => {
            return v.name == 'customer'
          });

          if(arr == 1) {
            this.$refs.addCustomerContractModal.visible = true;
            this.$refs.addCustomerContractModal.title = '新增客户合同';
            this.$refs.addCustomerContractModal.addType = 1;
            this.$refs.addCustomerContractModal.firstPageAdd();
          } else {
            this.$message.error('暂无权限');
          }
        }
      },
      // 新增退货订单
      addGoodsRejectedOrder() {
        if(!this.set) {
          this.$refs.goodsRejectedOrderModal.visible = true;
          this.$refs.goodsRejectedOrderModal.title = '新增采购退货单';
          this.$refs.goodsRejectedOrderModal.loadSupplierData();
          this.$refs.goodsRejectedOrderModal.loadDepositoryData();
          this.$refs.goodsRejectedOrderModal.loadUserListData();
        }
      },
      // 新增采购入库订单
      addInDepositoryOrder() {
        if(!this.set) {
          this.$refs.inDepositoryOrderModal.title = "新增采购入库订单"
          this.$refs.inDepositoryOrderModal.addInDepositoryOrder();
          this.$refs.inDepositoryOrderModal.loadSupplierData();
          this.$refs.inDepositoryOrderModal.loadDepositoryData();
          this.$refs.inDepositoryOrderModal.loadUserListData();
        }
      },
      addOtherInDepositoryOrder() {
        if(!this.set) {
          this.$refs.otherInDepositoryOrderModal.title = "新增其他入库订单"
          this.$refs.otherInDepositoryOrderModal.addOtherInDepositoryOrder();
          this.$refs.otherInDepositoryOrderModal.loadDepositoryData();
        }
      },
      addAllocateTransfer(){
        if(!this.set) {
          this.$refs.allocateAndTransferModal.title = "新增调拨单"
          this.$refs.allocateAndTransferModal.addAllocateTransfer();
          this.$refs.allocateAndTransferModal.loadDepositoryData();
        }
      },
      addPurchaseOrder(){
        if(!this.set) {
          this.$refs.purchaseOrderModal.title = "新增采购订单"
          this.$refs.purchaseOrderModal.addPurchaseOrder();
          this.$refs.purchaseOrderModal.loadSupplierData();
          this.$refs.purchaseOrderModal.loadDepositoryData();
          this.$refs.purchaseOrderModal.loadUserListData();
        }
      },
      addCheck(){
        if(!this.set) {
          this.$refs.checkModal.title = "新增盘点"
          this.$refs.checkModal.addCheck();
          this.$refs.checkModal.loadDepositoryData();
        }
      },
      //新增其他入库单
      addOtherOutDepositoryOrder(){
        if(!this.set) {
          this.$refs.otherOutDepositoryOrderModal.title = "新增其他出库订单"
          this.$refs.otherOutDepositoryOrderModal.addOtherOutDepositoryOrder();
          this.$refs.otherOutDepositoryOrderModal.loadDepositoryData();
        }
      },
      addWorker(){
        if(!this.set) {
          this.$refs.ghWorkerInfoModal.title = '新增';
          this.$refs.ghWorkerInfoModal.add();
        }
      },
      selectCustomerInfo() {
        if(!this.set) {
          this.visible = true;
        }
      },
      onSearch(value) {
        this.data = [];
        if(value != null && value != '') {
          getAction(this.url.getCustomerInfo, {'telePhone': value})
          .then(res => {
            if (res.success) {
              this.data.push(res.result);
              this.isTxtShow = true;
              this.isShow = false;
            } else {
              this.isTxtShow = false;
              this.isShow = true;
              this.message = res.message
            }
          });
        }
      },
      delQuickPath(id) {
        deleteAction(this.url.delete, {
          id: id
        })
        .then(res => {
          if (res.success) {
            this.getQuickPathUser();
          }
        });
      },
      setting() {
        if(this.set) {
          this.set = false;
          this.getQuickPathUser();
        } else {
          this.set = true;
        }
      },
      _click(funcName) {
        if(funcName) {
          this[funcName]();
        }
      }
    }
  }
</script>
<style>
  .show {
    display: none;
  }
  .card {
    height: 100%;
  }
  #card .ant-card-body {
    height: 240px;
    overflow-y: auto;
  }
  .text-overflow{
    overflow:hidden;
    white-space:nowrap;
    text-overflow:ellipsis;
  }
</style>